package remote;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebService;
import jakarta.xml.ws.Endpoint;
import com.alibaba.fastjson.JSON;
import com.such.kit.string.StringCommons;

@WebService
public class WebServiceServer {

	@WebMethod(operationName = "simple")
	public String simple(@WebParam(
			name = "str") String str,
			@WebParam(name = "num") Integer num,
			@WebParam(name = "strAarray") String[] strAarray,
			@WebParam(name = "numArray") Integer[] numArray) {
		System.out.println(StringCommons.merger("Arg1：", str));
		System.out.println(StringCommons.merger("Arg2：", num));
		System.out.println(StringCommons.merger("Arg3：", StringCommons.merger(strAarray, " | ", true)));
		System.out.println(StringCommons.merger("Arg4：", StringCommons.merger(numArray, " | ", true)));
		return "call simple over";
	}

	@WebMethod(operationName = "collection")
	public Map<String, ArrayList<Integer>> collection(
			@WebParam(name = "list") ArrayList<String> list,
			@WebParam(name = "map") HashMap<String, ArrayList<Integer>> map) {
		System.out.println(StringCommons.merger("Arg1：", list));
		System.out.println(StringCommons.merger("Arg2：", map));
		return map;
	}

	@WebMethod(operationName = "complex")
	public List<Model> complex(@WebParam(name = "model") String modelJson) {
		System.out.println(modelJson);
		Model model = JSON.parseObject(modelJson, Model.class);
		List<WebServiceServer.Model> results = new ArrayList<WebServiceServer.Model>();
		results.add(model);
		return results;
	}

	public static class Model {

		private String str;
		private int num;
		private String[] array;
		private ArrayList<String> list;
		private HashMap<String, ArrayList<Integer>> map;

		/** [参考 {@link #str}] */
		public String getStr() {
			return this.str;
		}

		/** [参考 {@link #str}] */
		public void setStr(String str) {
			this.str = str;
		}

		/** [参考 {@link #num}] */
		public int getNum() {
			return this.num;
		}

		/** [参考 {@link #num}] */
		public void setNum(int num) {
			this.num = num;
		}

		/** [参考 {@link #array}] */
		public String[] getArray() {
			return this.array;
		}

		/** [参考 {@link #array}] */
		public void setArray(String[] array) {
			this.array = array;
		}

		/** [参考 {@link #list}] */
		public ArrayList<String> getList() {
			return this.list;
		}

		/** [参考 {@link #list}] */
		public void setList(ArrayList<String> list) {
			this.list = list;
		}

		/** [参考 {@link #map}] */
		public HashMap<String, ArrayList<Integer>> getMap() {
			return this.map;
		}

		/** [参考 {@link #map}] */
		public void setMap(HashMap<String, ArrayList<Integer>> map) {
			this.map = map;
		}

		@Override
		public String toString() {
			return "Model [str=" + str + ", num=" + num + ", array=" + Arrays.toString(array) + ", list=" + list + ", map=" + map + "]";
		}

	}

	public static void main(String[] args) {
		Endpoint.publish("http://localhost:8081/web-service/test", new WebServiceServer());   
	}

}
